<title> </title>

<a href = "../index.html">
<IMG SRC="../home_motif.gif" ALIGN=bottom>
</a>
<a href = "index.html">
<IMG SRC="../toc_motif.gif" ALIGN=bottom>
</a>
<a href = "chpt5.html">
<IMG SRC="../previous_motif.gif" ALIGN=bottom>
</a>
<a href = "chpt7.html">
<IMG SRC="../next_motif.gif" ALIGN=bottom>
</a>

<hr>

<h2> Chapter 6: Reading from Files and Storing/Extracting Between Structures </h2>

Now that we have tracked the features through the entire image
sequence and have saved the result to a file, we can read the
file and access the data without having to process the images again.
The following example shows how this is done. Once again, we will examine the
unfamiliar lines.<p>

<b>KLTReadFeatureTable()</b> reads the feature table from the
file "features.txt".  Since the first parameter is <code>NULL</code>, a feature
table of the appropriate size is created and returned.<p>

<b>KLTExtractFeatureList()</b> copies the <i>(i+1)</i>th column of
a feature table into a feature list, where <i>i</i> is given by the
third parameter (in this case 1).  In other words, <i>i=0</i> refers to
the first column.<p>

Although in this example the call <b>KLTReadFeatureList()</b> is
unnecessary, it is given here to show its syntax, which is identical
to that of KLTReadFeatureTable().  Because the first parameter is
not <code>NULL</code>, the data is written into the given feature list.<p>

<b>KLTStoreFeatureList()</b> copies a feature list into a 
particular column of a feature table (in this case the third column, for
which <i>i=2</i>).  Now, the 
second and third columns of the table are identical.<p>

The second half of this example involves a <b>feature history</b>,
which is a single row of a feature table in the same way
that a feature list is a single column.  That is, a feature
history contains a particular features' locations in all the
frames.  The syntax for dealing with a feature history is identical to
that of a feature list and should be clear from the example.<p>

NOTE:  Unlike this example, in which every KLTWriteFeature...() call
produces a text file, you will most likely want to produce binary
files.  See the explanation in Chapter 2.<p>

<hr>

<h3> Example 4</h3>

<pre width=80>
/**********************************************************************
Reads the feature table from "features.txt", copies the features from 
the second frame to those of the third frame, writes the features to 
"feat2.txt", and writes the new feature table to "ft2.txt".  Then the
eighth feature is overwritten with the fifth feature, and the resulting
table is saved to "ft3.txt".
**********************************************************************/

#include &lt;stdio.h&gt;
#include "klt.h"

void main()
{
     KLT_FeatureList fl;
     KLT_FeatureHistory fh;
     KLT_FeatureTable ft;
     int i;

     ft = KLTReadFeatureTable(NULL, "features.txt");
     fl = KLTCreateFeatureList(ft->nFeatures);
     KLTExtractFeatureList(fl, ft, 1);
     KLTWriteFeatureList(fl, "feat1.txt", "%3d");
     KLTReadFeatureList(fl, "feat1.txt");
     KLTStoreFeatureList(fl, ft, 2);
     KLTWriteFeatureTable(ft, "ft2.txt", "%3d");

     fh = KLTCreateFeatureHistory(ft->nFrames);
     KLTExtractFeatureHistory(fh, ft, 5);

     printf("The feature history of feature number 5:\n\n");
     for (i = 0 ; i < fh->nFrames ; i++)
          printf("%d: (%5.1f,%5.1f) = %d\n",
               i, fh->feature[i]->x, fh->feature[i]->y, fh->feature[i]->val);

     KLTStoreFeatureHistory(fh, ft, 8);
     KLTWriteFeatureTable(ft, "ft3.txt", "%6.1f");
}
</pre>

<hr>

<a href = "../index.html">
<IMG SRC="../home_motif.gif" ALIGN=bottom>
</a>
<a href = "index.html">
<IMG SRC="../toc_motif.gif" ALIGN=bottom>
</a>
<a href = "chpt5.html">
<IMG SRC="../previous_motif.gif" ALIGN=bottom>
</a>
<a href = "chpt7.html">
<IMG SRC="../next_motif.gif" ALIGN=bottom>
</a>

